function handlerRTCFunction(socket) {
  const id = socket.id;
  console.log(">>>>>>>>>>>>>>RTC", id);
  const userinfo = socket.handshake.query;
  const { username, now, avatar } = userinfo;
  const nowUserInfo = { username, socketId: socket.id, now, avatar };

  // 收到offer  发送给 B 端
  socket.on("offer", (res) => {
    console.log("offer>>>>");
    const { user } = res;
    socket.to(user.socketId).emit("peer-offer", {
      offer: res.offer,
      user: nowUserInfo,
    });
  });
  // 转发给A端
  socket.on("answer", (res) => {
    console.log("answer>>>>");
    const { user } = res;
    socket.to(user.socketId).emit("peer-answer", res);
  });

  //服务器接收candidate
  socket.on("candidate", (res) => {
    console.log("服务端接收candidate");

    socket.to(res.user.socketId).emit("peer-candidate", res);
  });
}

module.exports = {
  handlerRTCFunction,
};
